import request from '../utils/request'

// 添加订单
export const createOrder = (data) => {
  return request({
    url: '/orders',
    method: 'post',
    data
  })
}

// 根据用户id查询订单
export const getOrdersByUserId = (userId) => {
  return request({
    url: `/orders/listOrdersByUserId/${userId}`,
    method: 'get'
  })
}

// 根据订单id查询订单
export function getOrderById(orderId) {
  return request({
    url: '/orders/' + orderId,
    method: 'get'
  })
}

// 获取订单商品详情
export const getOrderDetails = (orderId) => {
  console.log('请求订单商品详情，订单ID:', orderId);
  return request({
    url: `/orderDetail/listOrderDetailByOrderId/${orderId}`,
    method: 'get'
  })
}

// 更新订单状态和支付方式
export const updateOrderStatus = (orderData) => {
  return request({
    url: '/orders',
    method: 'put',
    data: orderData
  });
};

// 删除订单
export const deleteOrderApi = (orderId) => {
  return request({
    url: `/orders/${orderId}`,
    method: 'delete'
  })
}

// 取消订单
export const cancelOrderApi = (orderId) => {
  return request({
    url: `/orders/cancel/${orderId}`,
    method: 'put'
  })
}

// 商家确认收货
export const confirmOrder = (orderId, businessId) => {
  return request({
    url: '/orders/confirm',
    method: 'post',
    params: {
      orderId,
      businessId
    }
  })
}
